﻿namespace Huayou.UI.WebControls
{
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Drawing;
    using System.Drawing.Design;
    using System.IO;
    using System.Reflection;
    using System.Runtime.CompilerServices;
    using System.Web.UI;
    using System.Web.UI.Design;
    using System.Web.UI.WebControls;
    using System.Xml;

    [ToolboxData("<{0}:WebMenu runat=server></{0}:WebMenu>"), ToolboxBitmap(typeof(WebMenu), "Huayou.UI.WebControls.WebMenu.bmp"), DefaultProperty("MenuData"), DefaultEvent("MenuItemSelected")]
    public class WebMenu : WebControl, IPostBackEventHandler
    {
        private WebMenuAlignment _Alignment;
        private string _BaseURL;
        private bool _CausesValidation;
        private string _ClientScriptLocation;
        private string _ContextControlID;
        private string _DefaultGroupCssClass;
        private string _DefaultItemCssClass;
        private string _DefaultItemCssClassDown;
        private string _DefaultItemCssClassOver;
        private int _DefaultItemSpacing;
        private string _DefaultTarget;
        private string _DownLevelIncludeFile;
        private int _EffectDuration;
        private int _ExpandDelay;
        private WebMenuEffect _ExpandEffect;
        private WebMenuAlignment _FloatingAlignment;
        private int _FloatingOffsetX;
        private int _FloatingOffsetY;
        private bool _HideSelectElements;
        private string _ImagesBaseURL;
        private bool _IsContextMenu;
        private bool _IsMovable;
        private string _MenuData;
        private WebMenuStyle _MenuStyle;
        private int _OffsetX;
        private int _OffsetY;
        protected Color _ShadowColor;
        protected bool _ShadowEnabled;
        protected int _ShadowOffset;
        private int groupCount;
        public MenuGroups Groups;
        internal int IconCount;
        protected ArrayList ImageList;
        private int itemCount;
        internal XmlDocument MenuDataDoc;
        internal bool PerformPageValidate;
        internal string PostBackItemID;
        public XmlElement StartGroupNode;
        internal bool useDefaultStyle;

        [Description("Fires after a menu item is selected."), Category("Menu Events")]
        public event MenuItemSelectedEvent MenuItemSelected;

        public event EventHandler MenuStructureCreated;

        public WebMenu() : base("span")
        {
            this._CausesValidation = false;
            this._EffectDuration = 250;
            this._ExpandDelay = 0;
            this._HideSelectElements = true;
            this._ShadowColor = Color.DimGray;
            this._ShadowOffset = 4;
            this.groupCount = 0;
            this.itemCount = 0;
            this.IconCount = 0;
            this.ImageList = new ArrayList();
            this.PerformPageValidate = false;
            this.useDefaultStyle = false;
            this.Groups = new MenuGroups(this);
        }

        private void AddClientSideIDs(XmlNode curGroup)
        {
            this.groupCount++;
            this.SetClientSideID((XmlElement) curGroup, this.ClientID + "_group_" + this.groupCount.ToString());
            for (int i = 0; i < curGroup.ChildNodes.Count; i++)
            {
                this.itemCount++;
                this.SetClientSideID((XmlElement) curGroup.ChildNodes[i], this.ClientID + "_item_" + this.itemCount.ToString());
                if (curGroup.ChildNodes[i].HasChildNodes)
                {
                    this.AddClientSideIDs(curGroup.ChildNodes[i].ChildNodes[0]);
                }
            }
        }

        internal void AddToImageList(string ImageName)
        {
            if (!this.ImageList.Contains(ImageName))
            {
                this.ImageList.Add(ImageName);
            }
        }

        public override void Dispose()
        {
            base.Dispose();
        }

        private XmlElement FindMenuItemElement(XmlNode curGroupNode, string ItemID)
        {
            XmlElement element = null;
            int num;
            for (num = 0; num < curGroupNode.ChildNodes.Count; num++)
            {
                if ((curGroupNode.ChildNodes[num].Attributes["ID"] != null) && (curGroupNode.ChildNodes[num].Attributes["ID"].Value == ItemID))
                {
                    element = (XmlElement) curGroupNode.ChildNodes[num];
                }
            }
            for (num = 0; num < curGroupNode.ChildNodes.Count; num++)
            {
                if (curGroupNode.ChildNodes[num].HasChildNodes && (element == null))
                {
                    element = this.FindMenuItemElement(curGroupNode.ChildNodes[num].ChildNodes[0], ItemID);
                }
            }
            return element;
        }

        private MenuGroup FindParentMenuGroup(XmlNode curGroupNode, string ItemID)
        {
            MenuGroup group = null;
            int num;
            for (num = 0; num < curGroupNode.ChildNodes.Count; num++)
            {
                if ((curGroupNode.ChildNodes[num].Attributes["ID"] != null) && (curGroupNode.ChildNodes[num].Attributes["ID"].Value == ItemID))
                {
                    group = new MenuGroup((XmlElement) curGroupNode, this);
                }
            }
            for (num = 0; num < curGroupNode.ChildNodes.Count; num++)
            {
                if (curGroupNode.ChildNodes[num].HasChildNodes && (group == null))
                {
                    group = this.FindParentMenuGroup(curGroupNode.ChildNodes[num].ChildNodes[0], ItemID);
                }
            }
            return group;
        }

        private string getAlignmentString(WebMenuAlignment Alignment)
        {
            switch (Alignment)
            {
                case WebMenuAlignment.TopLeft:
                    return "topleft";

                case WebMenuAlignment.TopMiddle:
                    return "topmiddle";

                case WebMenuAlignment.TopRight:
                    return "topright";

                case WebMenuAlignment.BottomLeft:
                    return "bottomleft";

                case WebMenuAlignment.BottomMiddle:
                    return "bottommiddle";

                case WebMenuAlignment.BottomRight:
                    return "bottomright";
            }
            return "";
        }

        private string getCoreScript(string CoreScriptID)
        {
            string str = "";
            string str3 = CoreScriptID;
            if (str3 == null)
            {
                return str;
            }
            if (!(str3 == "IE4"))
            {
                if (str3 != "NN6")
                {
                    return str;
                }
            }
            else
            {
                if ((this.ClientScriptLocation != null) && File.Exists(this.Context.Server.MapPath(this.ClientScriptLocation + "IE4core.js")))
                {
                    return ("<script language=\"javascript\" src=\"" + this.ClientScriptLocation + "IE4core.js\" type=\"text/javascript\"></script>");
                }
                str = "<script language=javascript>";
                return (str + this.getResourceContent("Huayou.UI.JS.IE4core.js") + "</script>");
            }
            if ((this.ClientScriptLocation != null) && File.Exists(this.Context.Server.MapPath(this.ClientScriptLocation + "NN6core.js")))
            {
                return ("<script language=javascript src=\"" + this.ClientScriptLocation + "NN6core.js\" type=\"text/javascript\"></script>");
            }
            str = "<script language=javascript>";
            return (str + this.getResourceContent("Huayou.UI.JS.NN6core.js") + "</script>");
        }

        private MenuGroupRenderBase getMenuGroup(XmlElement groupNode)
        {
            if ((this.Context.Request.Browser.Browser == "IE") & (this.Context.Request.Browser.MajorVersion >= 4))
            {
                return new MenuGroupIE4(groupNode, this);
            }
            if ((this.Context.Request.Browser.Browser == "Netscape") & (this.Context.Request.Browser.MajorVersion >= 5))
            {
                return new MenuGroupNN6(groupNode, this);
            }
            return new MenuGroupDefault(groupNode, this);
        }

        private Huayou.UI.WebControls.MenuItem GetMenuItem(string ItemID)
        {
            return new Huayou.UI.WebControls.MenuItem(this.FindMenuItemElement(this.StartGroupNode, ItemID), this.FindParentMenuGroup(this.StartGroupNode, ItemID), this);
        }

        private string getResourceContent(string resourceID)
        {
            StreamReader reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceID));
            return reader.ReadToEnd();
        }

        internal void InitMenuDataProperties()
        {
            int num = 0;
            while ((this.MenuDataDoc.ChildNodes[num].NodeType != XmlNodeType.Element) || !(this.MenuDataDoc.ChildNodes[num].Name == "MenuData"))
            {
                num++;
            }
            XmlNode node = this.MenuDataDoc.ChildNodes[num];
            if ((node.Attributes["BaseURL"] != null) && (this.BaseURL == null))
            {
                this.BaseURL = node.Attributes["BaseURL"].Value;
            }
            if ((node.Attributes["ImagesBaseURL"] != null) && (this.ImagesBaseURL == null))
            {
                this.ImagesBaseURL = node.Attributes["ImagesBaseURL"].Value;
            }
            if ((node.Attributes["DefaultGroupCssClass"] != null) && (this.DefaultGroupCssClass == null))
            {
                this.DefaultGroupCssClass = node.Attributes["DefaultGroupCssClass"].Value;
            }
            if (node.Attributes["DefaultItemSpacing"] != null)
            {
                this.DefaultItemSpacing = int.Parse(node.Attributes["DefaultItemSpacing"].Value);
            }
            if ((node.Attributes["DefaultItemCssClass"] != null) && (this.DefaultItemCssClass == null))
            {
                this.DefaultItemCssClass = node.Attributes["DefaultItemCssClass"].Value;
            }
            if ((node.Attributes["DefaultItemCssClassOver"] != null) && (this.DefaultItemCssClassOver == null))
            {
                this.DefaultItemCssClassOver = node.Attributes["DefaultItemCssClassOver"].Value;
            }
            if ((node.Attributes["DefaultItemCssClassDown"] != null) && (this.DefaultItemCssClassDown == null))
            {
                this.DefaultItemCssClassDown = node.Attributes["DefaultItemCssClassDown"].Value;
            }
            if ((node.Attributes["DefaultTarget"] != null) && (this.DefaultTarget == null))
            {
                this.DefaultTarget = node.Attributes["DefaultTarget"].Value;
            }
            this.StartGroupNode = (XmlElement) node.ChildNodes[0];
        }

        internal bool IsDownLevelBrowser()
        {
            if ((this.Context.Request.Browser.Browser == "IE") & (this.Context.Request.Browser.MajorVersion >= 4))
            {
                return false;
            }
            if ((this.Context.Request.Browser.Browser == "Netscape") & (this.Context.Request.Browser.MajorVersion >= 5))
            {
                return false;
            }
            return true;
        }

        public void LoadMenuData(string MenuDataXml)
        {
            this.MenuDataDoc = new XmlDocument();
            this.MenuDataDoc.LoadXml(MenuDataXml);
            this.InitMenuDataProperties();
            if (this.MenuStructureCreated != null)
            {
                this.MenuStructureCreated(this, EventArgs.Empty);
            }
        }

        protected override void LoadViewState(object savedState)
        {
            if (savedState != null)
            {
                object[] objArray = (object[]) savedState;
                if (objArray[0] != null)
                {
                    base.LoadViewState(objArray[0]);
                }
                if (objArray[1] != null)
                {
                    this.LoadMenuData((string) objArray[1]);
                }
            }
        }

        protected virtual void OnMenuItemSelected(MenuItemSelectedEventArgs e)
        {
            if (this.MenuItemSelected != null)
            {
                this.MenuItemSelected(this, e);
            }
        }

        public void RaisePostBackEvent(string eventArgument)
        {
            MenuItemSelectedEventArgs e = new MenuItemSelectedEventArgs();
            e.ItemID = eventArgument;
            e.Item = this.GetMenuItem(eventArgument);
            this.PostBackItemID = eventArgument;
            this.OnMenuItemSelected(e);
        }

        protected override void Render(HtmlTextWriter output)
        {
            if (((this.FloatingAlignment != WebMenuAlignment.None) || (this.Alignment != WebMenuAlignment.None)) || this.IsContextMenu)
            {
                base.Attributes["style"] = "position:absolute;visibility:hidden;z-index:111;";
            }
            base.Render(output);
        }

        protected void RenderClientScript(HtmlTextWriter output)
        {
            string browser = this.Context.Request.Browser.Browser;
            if (browser != null)
            {
                if (!(browser == "IE"))
                {
                    if (browser == "Netscape")
                    {
                        if (this.Context.Request.Browser.MajorVersion >= 5)
                        {
                            this.RenderClientScriptNN6(output);
                        }
                        else if (this.Context.Request.Browser.MajorVersion == 4)
                        {
                            this.RenderClientScriptNN4(output);
                        }
                    }
                    else if ((browser == "Opera") && (this.Context.Request.Browser.MajorVersion == 6))
                    {
                        this.RenderClientScriptOpera6(output);
                    }
                }
                else if (this.Context.Request.Browser.MajorVersion >= 4)
                {
                    this.RenderClientScriptIE4(output);
                }
            }
        }

        protected void RenderClientScriptIE4(HtmlTextWriter output)
        {
            string str5;
            if (!this.Page.IsClientScriptBlockRegistered("aspnm_core_script"))
            {
                string str = "";
                str = (str + this.getCoreScript("IE4")) + "<script language=javascript>" + this.getResourceContent("Huayou.UI.JS.IE4corevars.js");
                if (!this.HideSelectElements)
                {
                    str = str.Replace("aspnm_hideSelectElems = true", "aspnm_hideSelectElems = false");
                }
                if (this.ShadowEnabled & this.supportShadows())
                {
                    str = str.Replace("var aspnm_shadowEnabled = false", "var aspnm_shadowEnabled = true").Replace("var aspnm_shadowColor = '#777777'", "var aspnm_shadowColor = '" + ColorTranslator.ToHtml(this.ShadowColor) + "'").Replace("var aspnm_shadowOffest = 4", "var aspnm_shadowOffest = " + this.ShadowOffset.ToString());
                }
                str = str + "</script>";
                output.Write(str);
                this.Page.RegisterClientScriptBlock("aspnm_core_script", str);
            }
            if (this.IsMovable && !this.Page.IsClientScriptBlockRegistered("aspnm_menu_move"))
            {
                string str2 = "<script language=javascript>";
                str2 = str2 + this.getResourceContent("Huayou.UI.JS.IE4move.js");
                if (this.FloatingAlignment != WebMenuAlignment.None)
                {
                    str2 = str2.Replace("_is_floating_menu_", "true");
                }
                else
                {
                    str2 = str2.Replace("_is_floating_menu_", "false");
                }
                str2 = str2 + "</script>";
                output.Write(str2);
                this.Page.RegisterClientScriptBlock("aspnm_menu_move", str2);
            }
            if (this.IsContextMenu && !this.Page.IsClientScriptBlockRegistered("aspnm_menu_context"))
            {
                string str3 = "<script language=javascript>";
                str3 = str3 + this.getResourceContent("Huayou.UI.JS.IE4context.js");
                if (this.ContextControlID == null)
                {
                    str3 = str3.Replace("_context_menu_", this.ClientID);
                }
                str3 = str3 + "</script>";
                output.Write(str3);
                this.Page.RegisterClientScriptBlock("aspnm_menu_context", str3);
            }
            if (this.IsContextMenu && (this.ContextControlID != null))
            {
                string str4 = "<script language=javascript>";
                str4 = ((str4 + "aspnm_contextMenus[aspnm_contextMenuCount] = '" + this.ClientID + "'; ") + "aspnm_contextControls[aspnm_contextMenuCount] = '" + this.ContextControlID + "'; ") + "aspnm_contextMenuCount++; " + "</script>";
                output.Write(str4);
            }
            if (!((this.FloatingAlignment == WebMenuAlignment.None) || this.Page.IsClientScriptBlockRegistered("aspnm_menu_float")))
            {
                str5 = this.getAlignmentString(this.FloatingAlignment);
                string str6 = "<script language=javascript>";
                str6 = (str6 + this.getResourceContent("Huayou.UI.JS.IE4float.js")).Replace("_floating_offsetX", this.FloatingOffsetX.ToString()).Replace("_floating_offsetY", this.FloatingOffsetY.ToString()).Replace("_floating_alignment", "'" + str5 + "'").Replace("_floating_menu_", "'" + this.ClientID + "'").Replace("_main_group_", "'" + this.StartGroupNode.Attributes["ClientSideID"].Value + "'") + "</script>";
                output.Write(str6);
                this.Page.RegisterClientScriptBlock("aspnm_menu_float", str6);
            }
            else if (this.Alignment != WebMenuAlignment.None)
            {
                str5 = this.getAlignmentString(this.Alignment);
                string str7 = "aspnm_positionMenu(document.all['" + this.ClientID + "'], '" + str5 + "', " + this.OffsetX.ToString() + ", " + this.OffsetY.ToString() + ");document.all['" + this.ClientID + "'].style.visibility='visible';";
                string str8 = "<script language=javascript>";
                str8 = ((str8 + str7) + "function window.onresize(){" + str7 + "}") + "</script>";
                output.Write(str8);
            }
        }

        protected void RenderClientScriptNN4(HtmlTextWriter output)
        {
        }

        protected void RenderClientScriptNN6(HtmlTextWriter output)
        {
            string str5;
            if (!this.Page.IsClientScriptBlockRegistered("aspnm_core_script"))
            {
                string str = "";
                str = (str + this.getCoreScript("NN6")) + "<script language=javascript>" + this.getResourceContent("Huayou.UI.JS.NN6corevars.js");
                if (!this.HideSelectElements)
                {
                    str = str.Replace("aspnm_hideSelectElems = true", "aspnm_hideSelectElems = false");
                }
                str = str + "</script>";
                output.Write(str);
                this.Page.RegisterClientScriptBlock("aspnm_core_script", str);
            }
            if (this.IsMovable && !this.Page.IsClientScriptBlockRegistered("aspnm_menu_move"))
            {
                string str2 = "<script language=javascript>";
                str2 = str2 + this.getResourceContent("Huayou.UI.JS.NN6move.js");
                if (this.FloatingAlignment != WebMenuAlignment.None)
                {
                    str2 = str2.Replace("_is_floating_menu_", "true");
                }
                else
                {
                    str2 = str2.Replace("_is_floating_menu_", "false");
                }
                str2 = str2 + "</script>";
                output.Write(str2);
                this.Page.RegisterClientScriptBlock("aspnm_menu_move", str2);
            }
            if (this.IsContextMenu && !this.Page.IsClientScriptBlockRegistered("aspnm_menu_context"))
            {
                string str3 = "<script language=javascript>";
                str3 = str3 + this.getResourceContent("Huayou.UI.JS.NN6context.js");
                if (this.ContextControlID == null)
                {
                    str3 = str3.Replace("_context_menu_", this.ClientID);
                }
                str3 = str3 + "</script>";
                output.Write(str3);
                this.Page.RegisterClientScriptBlock("aspnm_menu_context", str3);
            }
            if (this.IsContextMenu && (this.ContextControlID != null))
            {
                string str4 = "<script language=javascript>";
                str4 = ((str4 + "aspnm_contextMenus[aspnm_contextMenuCount] = '" + this.ClientID + "'; ") + "aspnm_contextControls[aspnm_contextMenuCount] = '" + this.ContextControlID + "'; ") + "aspnm_contextMenuCount++; " + "</script>";
                output.Write(str4);
            }
            if (!((this.FloatingAlignment == WebMenuAlignment.None) || this.Page.IsClientScriptBlockRegistered("aspnm_menu_float")))
            {
                str5 = this.getAlignmentString(this.FloatingAlignment);
                string str6 = "<script language=javascript>";
                str6 = (str6 + this.getResourceContent("Huayou.UI.JS.NN6float.js")).Replace("_floating_offsetX", this.FloatingOffsetX.ToString()).Replace("_floating_offsetY", this.FloatingOffsetY.ToString()).Replace("_floating_alignment", "'" + str5 + "'").Replace("_floating_menu_", "'" + this.ClientID + "'").Replace("_main_group_", "'" + this.StartGroupNode.Attributes["ClientSideID"].Value + "'") + "</script>";
                output.Write(str6);
                this.Page.RegisterClientScriptBlock("aspnm_menu_float", str6);
            }
            if (this.Alignment != WebMenuAlignment.None)
            {
                str5 = this.getAlignmentString(this.Alignment);
                string str7 = "<script language=javascript>";
                string str8 = str7;
                str7 = (str8 + "aspnm_positionMenu(document.getElementById('" + this.ClientID + "'), '" + str5 + "', " + this.OffsetX.ToString() + ", " + this.OffsetY.ToString() + ");document.getElementById('" + this.ClientID + "').style.visibility='visible';") + "</script>";
                output.Write(str7);
            }
        }

        protected void RenderClientScriptOpera6(HtmlTextWriter output)
        {
        }

        protected override void RenderContents(HtmlTextWriter output)
        {
            if (this.RunningInDesignMode())
            {
                this.RenderMessage(output, "Huayou 菜单控件1.0");
            }
            else if (this.IsDownLevelBrowser() && (this.DownLevelIncludeFile != null))
            {
                this.RenderDownLevelOutput(output);
            }
            else if ((this.MenuData == null) & (this.MenuDataDoc == null))
            {
                this.RenderMessage(output, "Please specify the <b>MenuData</b> XML file property.");
            }
            else if (this.warn())
            {
                this.RenderMessage(output, "Demo version. Purchase the full version <a href=http://www.aspnetmenu.com/pricing.aspx target=_blank><font color=silver>here</font></a>.");
            }
            else
            {
                if (!(this.Enabled && !this.IsDownLevelBrowser()))
                {
                    this.RenderDefaultStyleDefinitions(output);
                    this.RenderMainGroup(output, this.StartGroupNode);
                }
                else
                {
                    this.AddClientSideIDs(this.StartGroupNode);
                    this.RenderSubGroups(output, this.StartGroupNode);
                    this.RenderRolloverImages(output);
                    if (this.useDefaultStyle)
                    {
                        this.RenderDefaultStyleDefinitions(output);
                    }
                    this.RenderClientScript(output);
                }
                if (this.PerformPageValidate)
                {
                    this.Page.Validate();
                }
            }
        }

        protected void RenderDefaultStyleDefinitions(HtmlTextWriter output)
        {
            string str = "<style>";
            str = str + this.getResourceContent("CYBERAKT.WebControls.Navigation.defaultStyle.css") + "</style>";
            output.Write(str);
        }

        protected void RenderDownLevelOutput(HtmlTextWriter output)
        {
            FileStream stream = new FileStream(this.Context.Server.MapPath(this.DownLevelIncludeFile), FileMode.Open, FileAccess.Read);
            output.Write(new StreamReader(stream).ReadToEnd());
            stream.Close();
        }

        internal void RenderMainGroup(HtmlTextWriter output, XmlElement groupNode)
        {
            MenuGroupRenderBase base2 = this.getMenuGroup(groupNode);
            switch (this.MenuStyle)
            {
                case WebMenuStyle.ClassicHorizontal:
                    base2.Orientation = "horizontal";
                    break;

                case WebMenuStyle.ClassicVertical:
                    base2.Orientation = "vertical";
                    break;

                case WebMenuStyle.FreeStyle:
                    break;

                default:
                    base2.Orientation = "horizontal";
                    break;
            }
            base2.Render(output);
        }

        private void RenderMessage(HtmlTextWriter output, string Message)
        {
            output.Write("<span style=\"background-color:#3F3F3F;border:1px;border-style:solid;border-bottom-color:black;border-right-color:black;border-left-color:lightslategray;border-top-color:lightslategray;color:cornsilk;padding:2px;font-family:verdana;font-size:12px;");
            if (this.RunningInDesignMode())
            {
                output.Write("height:100%;");
            }
            if (this.Width.IsEmpty)
            {
                output.Write("\">");
            }
            else
            {
                output.Write("width:100%\">");
            }
            output.Write("<b>ASP.NET Menu</b> :: " + Message + "</span>");
        }

        protected void RenderRolloverImages(HtmlTextWriter output)
        {
            output.Write("<table style=\"position:absolute;top:0px;left:0px;visibility:hidden;\"><tr><td>");
            for (int i = 0; i < this.ImageList.Count; i++)
            {
                output.Write("<img src=\"" + this.ImageList[i] + "\" width=0 height=0>");
            }
            output.Write("</td></tr></table>");
        }

        protected void RenderSubGroups(HtmlTextWriter output, XmlElement groupNode)
        {
            if (groupNode == this.StartGroupNode)
            {
                this.RenderMainGroup(output, groupNode);
                output.RenderEndTag();
                output.RenderBeginTag("span");
            }
            else
            {
                MenuGroupRenderBase base2 = this.getMenuGroup(groupNode);
                if ((base2.Orientation == null) || (this.MenuStyle != WebMenuStyle.FreeStyle))
                {
                    base2.Orientation = "vertical";
                }
                base2.Render(output);
            }
            for (int i = 0; i < groupNode.ChildNodes.Count; i++)
            {
                if (groupNode.ChildNodes[i].HasChildNodes)
                {
                    this.RenderSubGroups(output, (XmlElement) groupNode.ChildNodes[i].ChildNodes[0]);
                }
            }
        }

        internal bool RunningInDesignMode()
        {
            return ((base.Site != null) && base.Site.DesignMode);
        }

        protected override object SaveViewState()
        {
            object obj2 = base.SaveViewState();
            object[] objArray = new object[2];
            objArray[0] = obj2;
            if (this.MenuDataDoc != null)
            {
                objArray[1] = this.MenuDataDoc.InnerXml;
            }
            return objArray;
        }

        private void SetClientSideID(XmlElement element, string newValue)
        {
            element.SetAttribute("ClientSideID", newValue);
        }

        internal bool supportEffects()
        {
            if (this.Context.Request.Headers["User-Agent"].IndexOf("NT 4") > 0)
            {
                return false;
            }
            if (this.Context.Request.Browser.Platform.StartsWith("Mac"))
            {
                return false;
            }
            return (((this.Context.Request.Browser.Browser == "IE") && (this.Context.Request.Browser.MajorVersion >= 6)) || (((this.Context.Request.Browser.Browser == "IE") && (this.Context.Request.Browser.MajorVersion == 5)) && (this.Context.Request.Browser.MinorVersion >= 5.0)));
        }

        internal bool supportShadows()
        {
            return ((this.Context.Request.Browser.Browser == "IE") && (this.Context.Request.Browser.MajorVersion >= 5));
        }

        private bool warn()
        {
            return false;
        }

        [Description("Use this property to align the menu to a specific corner of the page."), Category("Advanced Positioning")]
        public WebMenuAlignment Alignment
        {
            get
            {
                return this._Alignment;
            }
            set
            {
                this._Alignment = value;
            }
        }

        [Description("If specified, this value will be used as the prefix for all MenuItem URL attributes"), Category("MenuData")]
        public string BaseURL
        {
            get
            {
                return this._BaseURL;
            }
            set
            {
                this._BaseURL = value;
            }
        }

        [Category("Behavior"), Description("Whether the menu causes validation to fire. You can override this property using the CausesValidation attribute for individual menu items.")]
        public bool CausesValidation
        {
            get
            {
                return this._CausesValidation;
            }
            set
            {
                this._CausesValidation = value;
            }
        }

        [Category("Menu Structure"), Description("Directory where all ASP.NET Menu client scripts are stored. ")]
        public string ClientScriptLocation
        {
            get
            {
                return this._ClientScriptLocation;
            }
            set
            {
                this._ClientScriptLocation = value;
            }
        }

        [Category("Advanced Positioning"), Description("Client-side ID of the control for which this context menu will be used.")]
        public string ContextControlID
        {
            get
            {
                return this._ContextControlID;
            }
            set
            {
                this._ContextControlID = value;
            }
        }

        [Description("Default CSS class to be used for all menu groups."), Category("MenuData")]
        public string DefaultGroupCssClass
        {
            get
            {
                return this._DefaultGroupCssClass;
            }
            set
            {
                this._DefaultGroupCssClass = value;
            }
        }

        [Description("Default CSS class to be used for all menu items."), Category("MenuData")]
        public string DefaultItemCssClass
        {
            get
            {
                return this._DefaultItemCssClass;
            }
            set
            {
                this._DefaultItemCssClass = value;
            }
        }

        [Description("Default CSS class to be used for all menu items on mouse down."), Category("MenuData")]
        public string DefaultItemCssClassDown
        {
            get
            {
                return this._DefaultItemCssClassDown;
            }
            set
            {
                this._DefaultItemCssClassDown = value;
            }
        }

        [Category("MenuData"), Description("Default CSS class to be used for all menu items on mouse over.")]
        public string DefaultItemCssClassOver
        {
            get
            {
                return this._DefaultItemCssClassOver;
            }
            set
            {
                this._DefaultItemCssClassOver = value;
            }
        }

        [Category("MenuData"), Description("Default item spacing to be used for all menu groups.")]
        public int DefaultItemSpacing
        {
            get
            {
                return this._DefaultItemSpacing;
            }
            set
            {
                this._DefaultItemSpacing = value;
            }
        }

        [Description("Default target frame."), Category("MenuData")]
        public string DefaultTarget
        {
            get
            {
                return this._DefaultTarget;
            }
            set
            {
                this._DefaultTarget = value;
            }
        }

        [Category("Menu Structure"), Description("File containing the content to be sent to down-level browsers. If specified, it will override the default down-level rendering.")]
        public string DownLevelIncludeFile
        {
            get
            {
                return this._DownLevelIncludeFile;
            }
            set
            {
                this._DownLevelIncludeFile = value;
            }
        }

        [DefaultValue(250), Description("Effect duration in milliseconds."), Category("Expand/Collapse")]
        public int EffectDuration
        {
            get
            {
                return this._EffectDuration;
            }
            set
            {
                this._EffectDuration = value;
            }
        }

        [Category("Expand/Collapse"), Description("Number of milliseconds before a subgroup is expanded. Recommended value for comfortable menu navigation is 250.")]
        public int ExpandDelay
        {
            get
            {
                return this._ExpandDelay;
            }
            set
            {
                this._ExpandDelay = value;
            }
        }

        [Category("Expand/Collapse"), Description("Transition effect used for group expand.")]
        public WebMenuEffect ExpandEffect
        {
            get
            {
                return this._ExpandEffect;
            }
            set
            {
                this._ExpandEffect = value;
            }
        }

        [Description("Use this property to create floating menus."), Category("Advanced Positioning")]
        public WebMenuAlignment FloatingAlignment
        {
            get
            {
                return this._FloatingAlignment;
            }
            set
            {
                this._FloatingAlignment = value;
            }
        }

        [Category("Advanced Positioning"), Description("Horizontal offset from the window corner specified in the FloatingAlignment property.")]
        public int FloatingOffsetX
        {
            get
            {
                return this._FloatingOffsetX;
            }
            set
            {
                this._FloatingOffsetX = value;
            }
        }

        [Category("Advanced Positioning"), Description("Vertical offset from the window corner specified in the FloatingAlignment property.")]
        public int FloatingOffsetY
        {
            get
            {
                return this._FloatingOffsetY;
            }
            set
            {
                this._FloatingOffsetY = value;
            }
        }

        [Browsable(true), Description("Whether to hide HTML <select> elements on group expand."), Category("Expand/Collapse"), DefaultValue(false)]
        public bool HideSelectElements
        {
            get
            {
                return this._HideSelectElements;
            }
            set
            {
                this._HideSelectElements = value;
            }
        }

        [Description("If specified, this value will be used as the prefix for all MenuItem Image attributes."), Category("MenuData")]
        public string ImagesBaseURL
        {
            get
            {
                return this._ImagesBaseURL;
            }
            set
            {
                this._ImagesBaseURL = value;
            }
        }

        [Description("Whether this is a context menu."), Category("Advanced Positioning")]
        public bool IsContextMenu
        {
            get
            {
                return this._IsContextMenu;
            }
            set
            {
                this._IsContextMenu = value;
            }
        }

        [Category("Advanced Positioning"), Description("To make the menu movable, you must specify at least one 'Grip' item in the MenuData XML file, as well as use initial absolute positioning.")]
        public bool IsMovable
        {
            get
            {
                return this._IsMovable;
            }
            set
            {
                this._IsMovable = value;
            }
        }

        [Description("Path to the XML file containing the menu structure."), Editor(typeof(XmlUrlEditor), typeof(UITypeEditor)), Category("Menu Structure")]
        public string MenuData
        {
            get
            {
                return this._MenuData;
            }
            set
            {
                this._MenuData = value;
                if (this.Context != null)
                {
                    this.MenuDataDoc = new XmlDocument();
                    this.MenuDataDoc.Load(this.Context.Server.MapPath(this._MenuData));
                    this.InitMenuDataProperties();
                    if (this.MenuStructureCreated != null)
                    {
                        this.MenuStructureCreated(this, EventArgs.Empty);
                    }
                }
            }
        }

        [Description("Drawing style."), Category("Menu Structure")]
        public WebMenuStyle MenuStyle
        {
            get
            {
                return this._MenuStyle;
            }
            set
            {
                this._MenuStyle = value;
            }
        }

        [Category("Advanced Positioning"), Description("Horizontal offset from the window corner specified in the Alignment property.")]
        public int OffsetX
        {
            get
            {
                return this._OffsetX;
            }
            set
            {
                this._OffsetX = value;
            }
        }

        [Category("Advanced Positioning"), Description("Vertical offset from the window corner specified in the Alignment property.")]
        public int OffsetY
        {
            get
            {
                return this._OffsetY;
            }
            set
            {
                this._OffsetY = value;
            }
        }

        [Category("Drop Shadow"), Description("Shadow base color.")]
        public Color ShadowColor
        {
            get
            {
                return this._ShadowColor;
            }
            set
            {
                this._ShadowColor = value;
            }
        }

        [Category("Drop Shadow"), Description("Please use this feature carefully when combined with the ExpandEffect property. Only Fade, Pixelate and Dissolve effects are recommended.")]
        public bool ShadowEnabled
        {
            get
            {
                return this._ShadowEnabled;
            }
            set
            {
                this._ShadowEnabled = value;
            }
        }

        [DefaultValue(4), Category("Drop Shadow"), Description("Shadow distance from the expanded menu group.")]
        public int ShadowOffset
        {
            get
            {
                return this._ShadowOffset;
            }
            set
            {
                this._ShadowOffset = value;
            }
        }

        public MenuGroup TopGroup
        {
            get
            {
                if (this.MenuDataDoc == null)
                {
                    this.MenuDataDoc = new XmlDocument();
                    this.MenuDataDoc.InnerXml = "<MenuData><MenuGroup></MenuGroup></MenuData>";
                    this.StartGroupNode = (XmlElement) this.MenuDataDoc.ChildNodes[0].ChildNodes[0];
                }
                return new MenuGroup(this.StartGroupNode, this);
            }
        }

        public delegate void MenuItemSelectedEvent(object sender, MenuItemSelectedEventArgs e);
    }
}

